package org.happy.tester.common.http;

import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;

import java.util.concurrent.TimeUnit;

/**
 * Description
 *
 * @author baijingchuan
 * Date 2020/6/10
 **/
public enum OkHttpClientProvider {

    SINGLETON_CLIENT;

    private OkHttpClient httpClient;

    OkHttpClientProvider() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(120L, TimeUnit.SECONDS);
        builder.readTimeout(120L, TimeUnit.SECONDS);
        builder.writeTimeout(120L, TimeUnit.SECONDS);
        ConnectionPool connectionPool = new ConnectionPool(10, 120, TimeUnit.SECONDS);
        builder.connectionPool(connectionPool);
        httpClient = builder.build();
    }

    public OkHttpClient getInstance() {
        return httpClient;
    }
}
